<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Insert title here</title>
        <script type="text/javascript">
        	function writecookie(frm){
				document.cookie="test="+escape("test");
				document.cookie="loginname="+escape(frm.username.value);
				var newdate=new Date();
				newdate.setTime(newdate.getTime()+20*60*1000);
				document.cookie="expires="+newdate.toGMTString();
				alert(document.cookie);
			}
			function getinfor(){
				var newcookie=document.cookie;
				//alert(newcookie);
				var cookiep=newcookie.split(";");
				var cookieParts="";
				var cookiename2="";
				var cookievalue2="";
				for(var i=0;i<cookiep.length;i++){
					cookieParts=cookiep[i].split("=");
					cookiename2=cookieParts[0].trim();
					cookievalue2=unescape(cookieParts[1].trim());
					if(cookievalue2!="" && cookiename2=="loginname"){
						document.loginform.username.value=cookievalue2;
					}
					if(cookiename2=="hits"){
						var hitt=parseInt(cookievalue2)+1;
						document.cookie="hits="+hitt;
						document.getElementById("hits").innerHTML=hitt;
					}
				}
			}
			String.prototype.trim = function(){
			    // 用正则表达式将前后空格  
			    // 用空字符串替代。  
			    return this.replace(/(^\s*)|(\s*$)/g, "");
			}
			function deletecookie(){
				var newdate2=new Date();
				newdate2.setTime(newdate2.getTime()-20*60*1000);
				document.cookie="expires="+newdate2.toGMTString();
				alert(document.cookie);
			}
        </script>
    </head>
    <body onload="getinfor();">
    	<form name="loginform" action="" onsubmit="writecookie(this);">
    		hits:<span name="hits" id="hits"></span>
			<br>
			username:<input type="text" name="username"/>
			<br>
			password:<input type="password" name="password"/>
			<br>
			<input type="submit"/>
			<br>
			<input type="button" value="delete cookie" onclick="deletecookie();"/>
    	</form>
    </body>
</html>
